

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="https://dwj666.cn/%E6%A3%AE%E6%9E%97.png">
  <link rel="icon" href="https://dwj666.cn/%E6%A3%AE%E6%9E%97.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="主要了解错误日志、普通日志、慢查询日志的查询与应用">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  <meta name="description" content="主要了解错误日志、普通日志、慢查询日志的查询与应用">
<meta property="og:type" content="article">
<meta property="og:title" content="Mysql错误日志、普通日志、慢查询日志">
<meta property="og:url" content="http://example.com/2023/02/10/%E3%80%90mysql-%E6%97%A5%E5%BF%97%E3%80%91%E9%94%99%E8%AF%AF%E6%97%A5%E5%BF%97%E3%80%81%E6%99%AE%E9%80%9A%E6%97%A5%E5%BF%97%E3%80%81%E6%85%A2%E6%9F%A5%E8%AF%A2%E6%97%A5%E5%BF%97/index.html">
<meta property="og:site_name" content="藏色的个人博客">
<meta property="og:description" content="主要了解错误日志、普通日志、慢查询日志的查询与应用">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-02-10T03:02:17.494Z">
<meta property="article:modified_time" content="2023-02-10T03:02:19.890Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary_large_image">
  
  <title>Mysql错误日志、普通日志、慢查询日志 - 藏色的个人博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="/hexo-gujijih/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/hexo-gujijih/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/hexo-gujijih/","version":"1.8.12","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname"}},"search_path":"/hexo-gujijih/local-search.xml"};
  </script>
  <script  src="/hexo-gujijih/js/utils.js" ></script>
  <script  src="/hexo-gujijih/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/hexo-gujijih/">
      <strong>藏色的个人博客</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hexo-gujijih/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hexo-gujijih/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hexo-gujijih/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hexo-gujijih/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/hexo-gujijih/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('https://dwj666.cn/dmfj.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Mysql错误日志、普通日志、慢查询日志">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2023-02-10 11:02" pubdate>
        2023年2月10日 上午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.5k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      5 分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Mysql错误日志、普通日志、慢查询日志</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2023年2月10日 上午
                
              </p>
            
            <div class="markdown-body">
              <p>主要了解错误日志、普通日志、慢查询日志的查询与应用</p>
<span id="more"></span>
<h3 id="MySQL错误日志"><a href="#MySQL错误日志" class="headerlink" title="MySQL错误日志"></a>MySQL错误日志</h3><p>Mysql错误日志主要用于记录MySQL服务实例每次启动、停止的详细信息，以及MySQL服务实例运行过程中产生的警告或者错误信息。与其他日志不同，MySQL错误日志必须开启，无法关闭。</p>
<h4 id="log-error"><a href="#log-error" class="headerlink" title="log_error"></a>log_error</h4><h5 id="设置了错误日志文件的物理位置（日志所在目录以及日志文件名）"><a href="#设置了错误日志文件的物理位置（日志所在目录以及日志文件名）" class="headerlink" title="设置了错误日志文件的物理位置（日志所在目录以及日志文件名）"></a>设置了错误日志文件的物理位置（日志所在目录以及日志文件名）</h5><p><code>show variables like &#39;log_error&#39;</code></p>
<p>当MySQL实例意外停止或者无法启动时，可以通过错误日志文件的内容分析产生故障的原因。</p>
<p>注意：MySQL错误日志不会记录所有的错误信息，只有MySQL服务实例运行过程中发生的关键信息才会被记录</p>
<h3 id="MySQL普通查询日志"><a href="#MySQL普通查询日志" class="headerlink" title="MySQL普通查询日志"></a>MySQL普通查询日志</h3><p>MySQL普通查询日志记录了MySQL服务实例的所有操作（例如查询语句、更新语句等），无论这些操作是否成功执行。</p>
<h4 id="general-log"><a href="#general-log" class="headerlink" title="general_log"></a>general_log</h4><p>设置了普通查询日志是否开启。</p>
<h5 id="查看慢日志是否开启"><a href="#查看慢日志是否开启" class="headerlink" title="查看慢日志是否开启"></a>查看慢日志是否开启</h5><p><code>show variables like &#39;general_log&#39;</code></p>
<h5 id="设置慢日志启用（0，关闭；1，启用）"><a href="#设置慢日志启用（0，关闭；1，启用）" class="headerlink" title="设置慢日志启用（0，关闭；1，启用）"></a>设置慢日志启用（0，关闭；1，启用）</h5><p><code>set @@global.general_log=1</code></p>
<h4 id="general-log-file"><a href="#general-log-file" class="headerlink" title="general_log_file"></a>general_log_file</h4><p>普通查询日志一旦开启，MySQL服务实例将自动创建普通查询日志，general_log_file参数设置了普通查询日志文件的物理位置（日志文件所在位置以及日志文件名）。</p>
<h5 id="查看普通日志文件的物理位置"><a href="#查看普通日志文件的物理位置" class="headerlink" title="查看普通日志文件的物理位置"></a>查看普通日志文件的物理位置</h5><p><code>show variables like &#39;general_log_file&#39;</code></p>
<p>注意：普通查询日志会消耗数据库性能，因此不建议开启。如果需要查询某些特殊的查询语句，可以临时打开普通查询日志。</p>
<h4 id="log-outpat"><a href="#log-outpat" class="headerlink" title="log_outpat"></a>log_outpat</h4><p>设置了普通查询日志的输出格式，默认File。</p>
<h5 id="查看日志的输出格式"><a href="#查看日志的输出格式" class="headerlink" title="查看日志的输出格式"></a>查看日志的输出格式</h5><p><code>show variables like &#39;log_outpat&#39;</code></p>
<p>设置慢日志的输出格式，设置成table可以将普通查询日志以及慢查询日志分别存储到mysql系统数据库中的general_log表以及slow_log表中（这两个表的存储引擎为CSV），可以通过sql语句<code>select * from mysql.general_log</code></p>
<p><code>set @@global.log_outpat=&quot;table&quot;</code></p>
<h3 id="MySQL慢查询日志"><a href="#MySQL慢查询日志" class="headerlink" title="MySQL慢查询日志"></a>MySQL慢查询日志</h3><p>MySQL慢查询日志可以有效跟踪【执行时间过长】或者【没有使用索引】的查询语句（包括select语句、update语句、delete语句以及insert语句）。</p>
<h4 id="slow-query-log"><a href="#slow-query-log" class="headerlink" title="slow_query_log"></a>slow_query_log</h4><p>设置设置了慢日志是否开启</p>
<h5 id="查看慢日志是否开启-1"><a href="#查看慢日志是否开启-1" class="headerlink" title="查看慢日志是否开启"></a>查看慢日志是否开启</h5><p><code>show variables like &#39;slow_query_log&#39;</code></p>
<h5 id="开启慢日志"><a href="#开启慢日志" class="headerlink" title="开启慢日志"></a>开启慢日志</h5><p><code>set @@global.slow_query_log=1</code></p>
<p>slow_query_log_file:设置了慢查询日志的物理地址</p>
<h4 id="long-query-time"><a href="#long-query-time" class="headerlink" title="long_query_time"></a>long_query_time</h4><p>设置了慢查询的时间阀值，默认是10秒。</p>
<h5 id="查看阀值"><a href="#查看阀值" class="headerlink" title="查看阀值"></a>查看阀值</h5><p><code>show variables like &#39;long_query_time&#39;</code></p>
<h5 id="设置阀值方法一"><a href="#设置阀值方法一" class="headerlink" title="设置阀值方法一"></a>设置阀值方法一</h5><p><code>set @@global.long_query_time=1</code></p>
<h5 id="设置阀值方法二"><a href="#设置阀值方法二" class="headerlink" title="设置阀值方法二"></a>设置阀值方法二</h5><p>可以在my.ini配置文件的【mysqlId】选项组中通过添加【long_query_time=1.00】将阀值设置为1秒。</p>
<h4 id="log-queries-not-using-indexes"><a href="#log-queries-not-using-indexes" class="headerlink" title="log_queries_not_using_indexes"></a>log_queries_not_using_indexes</h4><p> 是否将【没有使用索引的sql语句】记录到慢查询日志中，无论它的速度多快。</p>
<h5 id="查看该参数是否开启"><a href="#查看该参数是否开启" class="headerlink" title="查看该参数是否开启"></a>查看该参数是否开启</h5><p><code>show variables like &#39;log_queries_not_using_indexes&#39;</code></p>
<h5 id="设置参数"><a href="#设置参数" class="headerlink" title="设置参数"></a>设置参数</h5><p><code>set @@log_queries_not_using_indexes=1</code></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/hexo-gujijih/categories/mysql/">mysql</a>
                    
                      <a class="hover-with-bg" href="/hexo-gujijih/categories/mysql/%E8%BF%90%E7%BB%B4/">运维</a>
                    
                  </div>
                
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/hexo-gujijih/2023/02/10/sql%E7%AF%87-%E7%AE%97%E6%B3%95%E4%B8%80/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">sql刷题-计算用户的平均次日留存率</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/hexo-gujijih/2023/02/10/docker%E5%9F%BA%E7%A1%80%E7%AF%87%E4%B8%80/">
                        <span class="hidden-mobile">docker基础篇一</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="twikoo"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#comments', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/twikoo@1/dist/twikoo.all.min.js', function() {
        var options = Object.assign(
          {"envId":"blog9528-5gm3bi65f33458fb","region":"ap-shanghai","path":"window.location.pathname"},
          {
            el: '#twikoo',
            path: 'window.location.pathname',
            onCommentLoaded: function() {
              Fluid.plugins.initFancyBox('#twikoo .tk-content img:not(.tk-owo-emotion)');
            }
          }
        )
        twikoo.init(options)
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/hexo-gujijih/js/events.js" ></script>
<script  src="/hexo-gujijih/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/hexo-gujijih/js/local-search.js" ></script>



  
    <script  src="/hexo-gujijih/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/hexo-gujijih/js/boot.js" ></script>


</body>
</html>
